<?php

require('init.php');
//recoger id del sc para enviarlo nuevamente a add_comment.php cuando se diligencie el formulario
$id = $_REQUEST['id'];
require(LIBWWWDIR .'/forms.php');
require(LIBWWWDIR . '/header.php');?>
<!DOCTYPE>
<head>
<script type="text/javascript" src="../jquery-validation-1.9.0/lib/jquery.js" charset="utf-8"></script>
<script type="text/javascript" src="../jquery-validation-1.9.0/jquery.validate.js" charset="utf-8"></script>
<script type="text/javascript" src="../jquery-validation-1.9.0/additional-methods.js" charset="utf-8"></script>

<script type="text/javascript">
	$(document).ready(function(){
	$("#publishh").validate({
		rules:{
			bodytext: { required: true }
		},
		messages:{
			bodytext:{
				required: " Put a comment"
			}
			
		}
	});
	
	});
		
	
</script></head>
<h2> Add Comments</h2>
<?php echo addForm('add_comment.php?id='.$id, 'post', 'publishh');?>
<table><tr>
<td valign="top"><b><label for="bodytext">Text</label>:</b></td>
<td>
<?php echo addTextArea('bodytext', $body, 80, 10 );?>
</td></tr>

<td> <?php echo addSubmit('Publish', 'submit', "publishh.submit()");?>
</tr>
</table>
<?php echo addEndForm();

//insertar comment 
if ( isset($_POST['submit']) && !empty($_POST['bodytext']) )
{
		//guardar comentarios en db2
		$text = $_POST['bodytext'];
		add_comment($_REQUEST['id'], now(), $login, $text, $conn_db2);
		//una vez inserte, mande al header de la pagina anterior
		header('Location: source_code.php?id='.$_REQUEST['id']);
}

require(LIBWWWDIR . '/footer.php');

?>
</html>
